<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Point extends CI_Controller {

          public function __construct(){
                        parent::__construct();
                        $this->load->model(array("pointmodel"));
                }


  public function index()
  {
    $point_list=$this->pointmodel->get_point_list();
    
                       $data=array();
                       $data['point_list']=$point_list;
                       // $data['roles']=$roles;
    load($this->db,$this->session,$this->load,"point","index",$data);
  }


  public function get_point(){//获取所有积分兑换列表
   
    $arr=$this->pointmodel->get_point();
   
             $str=json_encode($arr);
             echo $str;
    
  }


  public function adddb(){
                 $arr=$_REQUEST;     
                   $name=$arr['name'];
                   $change_num=$arr['change_num'];
                  
                   $point_list=$arr['point_list'];
                   $sale=$arr['sale'];
                 
                   $arr=array(
                    "name"=>$name,
                    "change_num"=>$change_num,
                    
                    "point_list"=>$point_list,
                    "sale"=>$sale,
                    "del"=>0
                   
                    );

                   if($this->db->insert("point",$arr)){
                    success();
                   }

               
  }


  public function edit(){


    $id=$this->input->get("id");
  $arr=$this->input->post();
   
      $this->db->where('id',$id);
      if($this->db->update('point',$arr)){
              success();    
        }else{
             ajaxfail();
        }
                /* $arr=$_REQUEST;
                  $id=$arr['id'];
                  $point_list=$arr['point_list'];
                  
                   $name=$arr['name'];
                   $change_num=$arr['change_num'];
                   $sale=$arr['sale'];
                  
                   $sql="update `point` set `point_list`='$point_list',`name`='$name',`change_num`='$change_num',`sale`='$sale' where `id`='$id'";
                   if($this->db->query($sql)){
                    success();
                   }*/
                   
  }

  public function del(){
                $id = intval($_REQUEST['id']);
                 $sql="update point  set del=1 where id='$id'";
                          if($this->db->query($sql)){
                         success();
                              }else{}
             
             

  }
}
